Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
relative-url
Advanced tools
convert a partial url into an absolute url from your current location.
convert a partial url into an absolute url from your current location.
In the WebSocket api, it expects a fully qualified url, but this is awkward because we want to develop on localhost, and then deploy to a server with a proper domain, with a different port.
We want to create a WebSocket at a path, and get whatever domain we are on.
This module generalized wsurl
url
is your partial url, it will be described below.
location
should be your is window.location
or the output
of require('url').parse(absoluteUrl)
if you want to change the protocol, protocol map is a object mapping current to desired protocol.
for websockets, you'll probably want: {http: 'ws', https: 'wss'}
defaultProtocol
is what to set the protocol to otherwise.
for example, 'ws'
if defaultProtocol
is not provided
the output protocol will the the same as location.protocol
for the following location:
var location = {
protocol: 'http',
host: 'server.com',
pathname '/foo'
} //OR get this from window.location
var protocolMap = {http: 'ws', https: 'wss'}
var defaultProtocol : 'ws'
var rurl = require('relative-url')
function relative (url) {
return rurl(url, location, protocolMap, defaultProtocol)
}
and the above mentioned settings (suitable for websockets) output will be as following.
relative('/') // => ws://server.com/
relative('/bar') // => ws://server.com/bar
relative('//client.com') // => ws://client.com/
relative('//:9999') // => ws://server.com:9999/
relative('?q=search' // => ws://server.com/foo?q=search
note that // denotes the start of the host. if you want to set the port without changing the domain, you must still use // otherwise the url module will think it's a path. I considered detecting that, but then i saw this comment and got scared of learning too much about urls.
MIT
FAQs
convert a partial url into an absolute url from your current location.
The npm package relative-url receives a total of 338 weekly downloads. As such, relative-url popularity was classified as not popular.
We found that relative-url demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.